package isi_ib;

import java.util.ArrayList;
import java.util.Iterator;

import utiles_isi.dateutil;
import utiles_isi.isi_util;

public class is_coleccion_arrays {
	
	private ArrayList<isi_arrays> mediascache;
	boolean cachedb;
	
	public is_coleccion_arrays() {
		mediascache = new ArrayList<isi_arrays>();
		cachedb=false;
	}
	
	public void setCachedb(boolean cachedb_){
		cachedb=cachedb_;
		
	}
	
	
	public void AddValor(int index_,double value_,String desc_){
		if(index_<0) return;
		isi_arrays arr_ = 	getArray(desc_);
		//arr_.setCachedb(cachedb);
		if(arr_!=null) 
			{
			arr_.add(index_, value_); 
			}
		
	}
	public double getValor(int index_,String desc_){
		isi_arrays arr_ = 	getArray(desc_);
		if(arr_==null) return isi_util.ErrorDato;
		else {
			return (arr_.get(index_));
		  }
	}
	
	public void Add(String descrip_){
		int existe_=0;
		if(mediascache!=null){
			Iterator<isi_arrays> itr = mediascache.iterator();
			while (itr.hasNext()) {
				isi_arrays element = itr.next();
				if(element.descriptor.equals(descrip_)){existe_=1;break;}
				
			}	
		}
		
		if(existe_==0) {
			isi_arrays medianueva_= new isi_arrays(descrip_,0);	
			mediascache.add(medianueva_);
		}
		
	}
	
	public void Add(isi_arrays is_arr_){
		
		isi_arrays old_arr_=getArray(is_arr_.descriptor);
		
		if (old_arr_==null){
			mediascache.add(is_arr_);
		} 
		else {
			old_arr_.reset();
			old_arr_=is_arr_;
		}
		
		
	}
	 
	 public void reset_cahe(String serie){
		 if(mediascache==null) return;
		 isi_arrays ca_ =getArray(serie);
		 if(ca_!=null) ca_.reset();
		 
	 }
	 public void reset_cahe()
	 {
	if(mediascache==null) return;
		 Iterator<isi_arrays> itr = mediascache.iterator();
		while (itr.hasNext()) {
					isi_arrays element = itr.next();
					if(!element.descriptor.equals("datos"))	element.reset();
					
				}
	 }
	 
	 public void reset_cahe_all()
	 {
	if(mediascache==null) return;
		 Iterator<isi_arrays> itr = mediascache.iterator();
		while (itr.hasNext()) {
					isi_arrays element = itr.next();
					element.reset();
					
				}
	 }
	 
	 
	 
	 public boolean existeArray(String desc_){
		 boolean existe_=false;
		 if(mediascache==null) return false;
		 Iterator<isi_arrays> itr = mediascache.iterator();
			while (itr.hasNext()) {
							isi_arrays element = itr.next();
							if(element.descriptor.equals(desc_)) {existe_=true;break;}
							
						}
			return existe_;
		 
	 }
	 
	 
	 
	 public isi_arrays getArray(String desc_){
		if(mediascache==null) return null;	
		 Iterator<isi_arrays> itr = mediascache.iterator();
			while (itr.hasNext()) {
							isi_arrays element = itr.next();
							if(element.descriptor.equals(desc_)) return element;
							
						}	
		
		return null;
	 }
	 
	 public int Count(String decrip_){
		 isi_arrays valores_=getArray(decrip_);
		 if(valores_!=null)		 return valores_.Count();
		 else return 0;
	 }

}
